<html>
<head><meta charset="utf-8"><title>paired associated type &amp; method specialization · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html">paired associated type &amp; method specialization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="162253507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162253507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162253507">(Apr 01 2019 at 16:13)</a>:</h4>
<p>This code fails:</p>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(specialization)]</span><span class="w"></span>

<span class="cp">#[derive(Debug)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Wrapper</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">ToWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Inner</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">to_wrap</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Wrapper</span><span class="o">&lt;</span><span class="n">Self</span>::<span class="n">Inner</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="n">default</span><span class="w"> </span><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">ToWrapper</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Inner</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">T</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">to_wrap</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Wrapper</span><span class="o">&lt;</span><span class="n">Self</span>::<span class="n">Inner</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Wrapper</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>From <a href="https://stackoverflow.com/q/51022636/155423" target="_blank" title="https://stackoverflow.com/q/51022636/155423">this Q&amp;A</a>, it's stated that's because we might specialize either <code>Inner</code> or <code>to_wrap</code> separately from the other, which means that the default implementation might be broken.</p>



<a name="162253590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162253590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162253590">(Apr 01 2019 at 16:14)</a>:</h4>
<p>That much makes sense to me, but is there a way of stating that an associated type and method must be specialized together?</p>



<a name="162253783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162253783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162253783">(Apr 01 2019 at 16:16)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  see discussion in <a href="https://github.com/rust-lang/rfcs/pull/2532" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2532">https://github.com/rust-lang/rfcs/pull/2532</a></p>



<a name="162253949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162253949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162253949">(Apr 01 2019 at 16:18)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/pull/2532#issuecomment-453719623" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2532#issuecomment-453719623">A Graydon approval</a>, nice</p>



<a name="162254003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162254003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162254003">(Apr 01 2019 at 16:19)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> the only relevant comment I see that mentions specialization is <a href="https://github.com/rust-lang/rfcs/pull/2532#issuecomment-429128002" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2532#issuecomment-429128002">this one</a></p>



<a name="162254072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162254072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162254072">(Apr 01 2019 at 16:20)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> and read the RFC <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="162254109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162254109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162254109">(Apr 01 2019 at 16:20)</a>:</h4>
<p>especially "future work"</p>



<a name="162254144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162254144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162254144">(Apr 01 2019 at 16:20)</a>:</h4>
<blockquote>
<p>GitHub Pages is temporarily down for maintenance.</p>
</blockquote>
<p>sigh</p>



<a name="162254298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162254298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162254298">(Apr 01 2019 at 16:22)</a>:</h4>
<p>So the answer is "no"</p>



<a name="162254427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162254427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162254427">(Apr 01 2019 at 16:24)</a>:</h4>
<p>Any feelings on when the future work might be considered again?</p>



<a name="162256047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/paired%20associated%20type%20%26%20method%20specialization/near/162256047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/paired.20associated.20type.20.26.20method.20specialization.html#162256047">(Apr 01 2019 at 16:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> I think the RFC should be stabilized first before we reconsider</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>